#ifndef _SHARE_H_
#define _SHARE_H_

#include <head.h>

#define err_log(errlog) do{                    \
							perror(errlog);    \
							exit(EXIT_FAILURE);\
							}while(0)

#define N 1024

typedef int DATATYPE;

typedef struct node{
	DATATYPE data;
	struct node *next;
}LinkNode;

typedef struct {
	int user_type;
	char action_type;
	int id;
	char name[N];
	int password;
	char sex;
	int age;
	int wage;
	char data[N];
}MSG;

typedef struct {
	int fd;
	MSG msg;
	sqlite3 *db;
}ARG;

extern LinkNode *Create_linklist();
extern int Insert_head_linklist(LinkNode *head, DATATYPE data);
extern int Delete_node(LinkNode *head, DATATYPE data);
extern int Sort_linklist(LinkNode *head);
extern int Insert_sort_linklist(LinkNode *head, DATATYPE data);
extern int TCP_server_sockfd_init(const char *argv1, const char *argv2, struct sockaddr_in *serveraddr);
extern int TCP_client_sockfd_init(const char *argv1, const char *argv2, struct sockaddr_in *serveraddr);
extern int TCP_REUSEADDR_sockfd_init(const char *argv1, const char *argv2, struct sockaddr_in *serveraddr);
extern int UDP_server_sockfd_init(const char *argv1, const char *argv2, struct sockaddr_in *serveraddr);
extern int UDP_client_sockfd_init(const char *argv1, const char *argv2, struct sockaddr_in *clientaddr);
extern int UDP_broadcast_snd_sockfd_init(const char *argv1, const char *argv2, struct sockaddr_in *broadcastaddr);
extern int UDP_multicast_recv_sockfd_init(const char *argv1, const char *argv2, struct sockaddr_in *multiaddr);
extern int TCP_server_local_sockfd_init(const char argv1, struct sockaddr_un *serveraddr);
extern int TCP_client_sockfd_init(const char *argv1, const char *argv2, struct sockaddr_in *serveraddr);
extern int TCP_client_local_sockfd_init(const char argv1, struct sockaddr_un *serveraddr);
extern int UDP_sever_local_sockfd_init(const char *argv1, struct sockaddr_un *serveraddr);
extern int UDP_client_local_sockfd_init(const char *argv1, const char *argv2, struct sockaddr_un *serveraddr);

extern sqlite3 *open_db(const char *filename);
extern void create_record_table(sqlite3 *ppDb);
extern int create_usr_table(sqlite3 *ppDb);
extern void create_dict_English_table(sqlite3 *ppDb);
extern void create_dict_chinese_table(sqlite3 *ppDb);
extern int insert_usrmsg(sqlite3 *ppDb, MSG usr);
extern int insert_usr_record(sqlite3 *ppDb, MSG usr);
extern int select_usrmsg(sqlite3 *ppDb, MSG usr);
extern int usr_callback(void *arg, int f_num, char **f_value, char **f_name);
extern int select_usr_record(sqlite3 *ppDb, MSG usr, int fd);
extern int select_usr(ARG *arg);
extern int select_usrall(ARG *arg);
extern int delete_usr(sqlite3 *ppDb, MSG usr);
extern int update_usr(sqlite3 *ppDb, MSG usr);

#endif
